//
//  CommentsTableViewCell.m
//  项目A_百思不得姐
//
//  Created by wudongyang on 16/5/31.
//  Copyright © 2016年 wudongyang. All rights reserved.
//

#import "CommentsTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation CommentsTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self DSSubViews];
    }
    return self;
}
-(void)DSSubViews{
    self.headImageView = [[UIImageView alloc] init];
    self.headImageView.backgroundColor = [UIColor whiteColor];
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = 25;
    [self.contentView addSubview:self.headImageView];
    
    self.nameLabel =[[UILabel alloc] init];
    self.nameLabel.backgroundColor = [UIColor clearColor];
    self.nameLabel.textColor = [UIColor grayColor];
    self.nameLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.nameLabel];
    
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.backgroundColor = [UIColor clearColor];
    self.timeLabel.textColor = [UIColor grayColor];
    self.timeLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.timeLabel];
    
    self.commentsLabel = [[UILabel alloc] init];
    self.commentsLabel.backgroundColor = [UIColor clearColor];
    self.commentsLabel.font = [UIFont systemFontOfSize:17];
    
    [self.contentView addSubview:self.commentsLabel];
    //自动换行
    self.commentsLabel.numberOfLines = 0;
    //自适应高度
    [self.commentsLabel sizeToFit];
    
    self.view = [UIView new];
    self.view.backgroundColor = DSRGBA(246, 246, 246, 1);
    [self.contentView addSubview:self.view];

}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.headImageView.frame = CGRectMake(10, 10, 50, 50);
    self.nameLabel.frame = CGRectMake(70, 10, 200, 25);
    self.timeLabel.frame = CGRectMake(70, 35, 200, 25);
    // 计算TitleLabel的高度
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17],NSFontAttributeName, nil];
    CGRect rect = [self.commentModel.content boundingRectWithSize:CGSizeMake(self.frame.size.width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.commentsLabel.frame = CGRectMake(70, 65, 280, rect.size.height);
    self.view.frame = CGRectMake(0, 70 + rect.size.height, self.contentView.frame.size.width, 1);
    
}
-(void)setCommentModel:(CommentsModel *)commentModel{
    _commentModel = commentModel;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:_commentModel.userModel.profile_image] placeholderImage:[UIImage imageNamed:@"tupian1.jpeg"]];
    self.nameLabel.text = _commentModel.userModel.username;
    self.timeLabel.text = _commentModel.ctime;
    self.commentsLabel.text = _commentModel.content;
}

@end
